//
//  MLWTipsICookTagCell.m
//  KITCHEN_STORIES
//
//  Created by 孟令通 on 16/6/13.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWTipsICookTagCell.h"

#import "MLWBaseView.h"



@implementation MLWTipsICookTagCell

- (void)dealloc
{
    
    [_stepDataArray release];
    
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.stepDataArray = [NSArray array];
        
        self.materialDataArray = [NSArray array];
        
        self.knowledgeDataArray = [NSArray array];
        
        self.otherDataArray = [NSArray array];
        
        self.pageMenu = @[@"做法", @"食材", @"相关常识", @"相宜相克"];
        
        self.pageView = [[YKPageView alloc] initWithFrame:self.contentView.bounds];
        
        self.pageView.delegate = self;
        
        self.pageView.dataSource = self;
        
        self.pageView.selectIndex = 0;
        
        self.pageView.menuViewStyle = YKMenuViewStyleLine;
        
        [self.contentView addSubview:_pageView];
        [_pageView release];
        
    }
    return self;
}

// 刷新分页
-(void)setStepDataArray:(NSArray *)stepDataArray
{
    if (_stepDataArray != stepDataArray) {
        
        [_stepDataArray release];
        
        _stepDataArray = [stepDataArray retain];
        
        [self.pageView reloadData];
        
    }
}

#pragma mark - page view datasource
// Menu的标题用NSArray封装，内为NSString
- (NSArray *)menuItemsForMenuViewInPageView:(YKPageView *)pageView {
    
    return self.pageMenu;
    
}

- (YKPageCell *)pageView:(YKPageView *)pageView cellForIndex:(NSInteger)index {
    
//    static NSString *identifier = @"pageCell";
    
    if (index == 0) {
       
        MLWTipsICookStepCell *cell = [pageView dequeueReusableCellWithIdentifier:@"step"];
        
        if (cell == nil) {
            
            cell = [[MLWTipsICookStepCell alloc] initWithIdentifier:@"step"];
            cell.stepCellDelegate = self;
        }
        
        cell.stepArray = [self.stepDataArray retain];
        
        
//        cell.backgroundColor = [UIColor colorWithRed:0.11 green:0.73 blue:0.61 alpha:1.00];
        cell.backgroundColor = [UIColor whiteColor];
        
        return cell;
        
    }
    else if (index == 1)
    {
        
        MLWTipsICookMaterialCell *cell = [pageView dequeueReusableCellWithIdentifier:@"material"];
        
        if (cell == nil) {
            
            cell = [[MLWTipsICookMaterialCell alloc] initWithIdentifier:@"material"];

        }
        
        cell.materialArray = [self.materialDataArray retain];
        
        cell.backgroundColor = [UIColor whiteColor];
        
        [cell getHeithgWithNumber:12 PageHeight:^(CGFloat fNumber) {
            
            NSLog(@"%f", fNumber);
            
        }];
        
        return cell;
        
    }
    else if (index == 2)
    {
        MLWTipsICookKnowledgeCell *cell = [pageView dequeueReusableCellWithIdentifier:@"knowledge"];
        
        if (cell == nil) {
            
            cell = [[MLWTipsICookKnowledgeCell alloc] initWithIdentifier:@"knowledge"];
            
        }
        
        cell.knowledgeArray = [self.knowledgeDataArray retain];
        
        cell.backgroundColor = [UIColor whiteColor];
        
        return cell;
    }
    else if(index == 3)
    {
        
        MLWTipsICookOtherCell *cell = [pageView dequeueReusableCellWithIdentifier:@"other"];
        
        if (cell == nil) {
            
            cell = [[MLWTipsICookOtherCell alloc] initWithIdentifier:@"other"];
            
        }
        
        cell.otherArray = self.otherDataArray;
        
//        cell.backgroundColor = [UIColor colorWithRed:0.99 green:0.75 blue:0.18 alpha:1.00];
        
        return cell;

        
    }
    
    
    return nil;
}

#pragma mark Page view delegate
// 若不实现，默认红黑，为保证字体颜色渐变，请尽量选用RGBA来创建UIColor
- (UIColor *)titleColorOfMenuItemInPageView:(YKPageView *)pageView withState:(YKMenuItemTitleColorState)state {
    
//    return [UIColor colorWithRed:0.04 green:0.04 blue:0.04 alpha:1.00];
    
    return [UIColor colorWithRed:1.00 green:0.47 blue:0.21 alpha:1.00];
    
}

// 若不实现,默认为30
- (CGFloat)pageView:(YKPageView *)pageView heightForMenuView:(YKMenuView *)menuView{
    
    return 43.5;
    
}

// 若不实现，默认为15/18
- (CGFloat)titleSizeOfMenuItemInPageView:(YKPageView *)pageView withState:(YKMenuItemTitleSizeState)state {
    
    switch (state) {
            
        case YKMenuItemTitleSizeStateNormal:
            
            return 14;
            
            break;
            
        case YKMenuItemTitleSizeStateSelected:
            
            return 16;
            
        default:
            break;
    }
}

// 若不实现，默认为灰色
- (UIColor *)backgroundColorOfMenuViewInPageView:(YKPageView *)pageView {
    
    return [UIColor colorWithRed:0.97 green:0.97 blue:0.97 alpha:1.00];
    
}

// MenuView 内部各个 item 的宽度，若标题过长可自行设置，默认为 60
- (CGFloat)pageView:(YKPageView *)pageView widthForMenuItemAtIndex:(NSInteger)index {
    
    return ScreenWidth / 4.0;
    
}

- (void)chengeCellHeightWithHeight:(CGFloat)height
{
    if ([self.tipsTagDelegate respondsToSelector:@selector(didChagendCellHeightWithHeight:)]) {
        
        [self.tipsTagDelegate didChagendCellHeightWithHeight:height];
        
    }
 
}

@end
